<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手后台</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#content,.nav_div{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content,.nav_div{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body>
<div id='content' style='position:relative;border:0px solid'>
	<h1 style='text-align:center'>公共数据库设置</h1>
	
	<div style='text-align:center'>
		<div style='margin:10px 0'>
			库　名：<input id='db_name' type="text" />
		</div>
		<div style='margin:10px 0'>
			库　址：<input id='db_addr' type="text" />
		</div>

		<button id='submit'>提交</button>
	</div>


</div>


</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
$(function(){
	//底部导航与显示页面
	$.ajax({
		url:'after_template_bottom_nav.html',
		success(res){
			$('body').append(res);
		}
	});


	//提交
	$('#submit').click(function(){
		var db_addr = $('#db_addr').val().trim();
		var db_name = $('#db_name').val().trim();
		if(sessionStorage.admin_public_database == JSON.stringify([db_name,db_addr])){
			A('没有变动！');
			return;
		}
		var data = {
			type:'public_database_set',
			db_addr:db_addr,
			db_name:db_name,
		};
		AjaxAfter(data,function(res){
			C(res);
			var tmp = JSON.parse(res);
			if(tmp.data){
				sessionStorage.admin_public_database = JSON.stringify(tmp.data);		//保存公共库信息
				sessionStorage.admin_token1 = tmp.token1;
			}
			A('设置成功！');
		});
	});


	//从local本地或upyun本地获取公共数据库
	ToGetData('/public_database/public.html',function(res){
		if(/^\[.*\]$/.test(res)){
			var tmp1 = JSON.parse(res);
			if(tmp1[0] && tmp1[1]){
				$('#db_addr').val(tmp1[1]);
				$('#db_name').val(tmp1[0]);
			}
		}
	});
});
</script>